<?php
/*
 * Evaluation
 * By Hylson, Helton and Jackson
 * Rio do Sul - Santa Catarina - BRASIL
 */

    require_once('../../config.php');
    require_once($CFG->libdir.'/dmllib.php');

    // Useful to get information about current user and course
    require_once($CFG->dirroot.'/user/profile/lib.php');

?>

<?php
    
/// Print the page header
    $strevaluations = get_string("modulenameplural", "evaluation");
    $strevaluation  = get_string("modulename", "evaluation");
		
    print_header_simple("", "",get_string('title','block_evaluationb'),
        "", "", true, update_module_button($cm->id, $course->id, $strevaluation), 
        navmenu($course, $cm));
?>

<hr/>

<?php
    /// Print the main part of the page 

    if (record_exists('evaluation','ispublic',1)) 
    {
        //show public evaluations
        $evaluations = get_records_sql("SELECT u.*, c.fullname 
			FROM {$CFG->prefix}evaluation u, {$CFG->prefix}course c 
			WHERE u.course=c.id");

        if (!empty($evaluations)) 
        {
            $es = $_REQUEST['evaluation'];

            $result = "<center><form method=post action=block_view.php>";
            $result .= get_string('select_public_evaluation','block_evaluationb').
                        '<br/><select name=evaluation>';
            foreach ($evaluations as $evaluation) {
                $name = $evaluation->name;
                $course_name = $evaluation->fullname;
                $result .= "<option value={$evaluation->id}";
                if ($evaluation->id == $es)
                  $result .=" SELECTED";
                $result .= ">$name ($course_name)</option>";
            }

            $result .= '</select>';
            $result .= '<input type=submit value="'.get_string('view_public_evaluation','block_evaluationb').'">';
            $result .= '</form></center>'; 

            //if there is an evaluation selected, show the history HERE! :-)
            if (!empty($es))
            {
                $s1 = get_string("dont_know", "evaluation");
                $s2 = get_string("bad", "evaluation");
                $s3 = get_string("regular", "evaluation");
                $s4 = get_string("good", "evaluation");
                $s5 = get_string("great", "evaluation");
                $s6 = get_string("excelent", "evaluation");

                $X = '<h2 align=center>'.
                    get_string('history_title','block_evaluationb').'</h2>';

                $rec_comments = 
                    get_records("evaluation_comments","evaluation",$es,"created desc");

                if (!empty($rec_comments))              
                {
		    $X=$X."<table border=3 bordercolor=green align=center class=body>";
		    $X=$X."<tr><td><b>".
		            get_string('comments','evaluation').
			    "</b></td><td><b>".
			    get_string('howwastheclass','evaluation').
			    "</b></td><td>".
			    get_string('when','evaluation').
			    "</td>";

                    if ($canseewho == 1)
		        $X=$X."<td>".get_string('who','evaluation')."</td>";
		    
		    $X=$X."</tr>";
		    	 
		    foreach ($rec_comments as $rec)
                    {
                        $comment = $rec->comment;
                        $grade = $rec->grade;
                        $created = $rec->created;

                        $X=$X."<tr>";

		        $X=$X."<td>".nl2br($comment)."</td>";
		        $X=$X."<td align=center>";
		        if ($grade == '0') $X=$X.$s1;
		        if ($grade == '1') $X=$X.$s2;
		        if ($grade == '2') $X=$X.$s3;
		        if ($grade == '3') $X=$X.$s4;
		        if ($grade == '4') $X=$X.$s5;
		        if ($grade == '5') $X=$X.$s6;
		        $X=$X. "</td>";

		        $X=$X. "<td align=center><img src=detail.gif title='".
                                $created."'></td>";

   		        $X=$X. "</tr>";
                    }
                    $X=$X. "</table>";
                }
                else
		    $X=$X. "<h3 align=center>".get_string('history_empty','block_evaluationb')."</h3>";

                $result .= $X;
	    }

            print_box($result, 'generalbox', 'intro'); 
        }
        else
            print_box(get_string('noevaluations','block_evaluationb'), 'generalbox', 'intro');
    } 
    else
        print_box(get_string('noevaluations','block_evaluationb'), 'generalbox', 'intro'); 
?>

<?php
/// Finish the page
    print_footer($course);
?>
